package com.grain.platform.em.yingji;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.Expose;
import com.grain.platform.entity.Foodstuff;
import com.grain.platform.entity.Granary;
import com.grain.platform.entity.Processors;
import com.grain.platform.entity.Transport;
import com.grain.platform.entity.Vehicle;

/**
 * 粮仓位置、运输单位、加工企业
 * @author Jay
 *
 */
@Component
public class EmergencyMap {
	
	@DataProvider
	public List<Granary> getGranary(){
		return granaryData();
	}
	
	@DataProvider
	public List<Foodstuff> getFoodstuffById(){
		return  foodstuffData();
	}
	
	@DataProvider
	public List<Vehicle> getVehicleById(){
		return  vehicleData();
	}
	/**
	 * 粮仓地图位置
	 * @param moveLng
	 * @return
	 */
	@Expose 
	public List<Granary> getMoveGranary(String moveLng){
		List<Granary> granaryLists = granaryData();
		List<Granary> granarys = new  ArrayList<Granary>();
		String[] strArray=moveLng.split(",");
		for (int i = 0; i < granaryLists.size(); i++) {
			BigDecimal longitude = granaryLists.get(i).getLongitude();
			BigDecimal getLatitude = granaryLists.get(i).getLatitude();
			BigDecimal latitude1 = new BigDecimal(strArray[1]);
			BigDecimal latitude2 = new BigDecimal(strArray[0]);
			BigDecimal longitude1 = new BigDecimal(strArray[2]);
			BigDecimal longitude2 = new BigDecimal(strArray[3]);
			if(longitude.compareTo(latitude1)>=0 || longitude.compareTo(latitude2)<=0 ||
					getLatitude.compareTo(longitude1)>=0 || getLatitude.compareTo(longitude2)>=0){
				granarys.add(granaryLists.get(i));
			}
		}
		return granarys;
				
	}
	
	/**
	 * 运输企业地图位置
	 * @param moveLng
	 * @return
	 */
	@Expose 
	public List<Transport> getMoveTransport(String moveLng){
		List<Transport> granaryLists = transportData();
		List<Transport> granarys = new  ArrayList<Transport>();
		String[] strArray=moveLng.split(",");
		for (int i = 0; i < granaryLists.size(); i++) {
			BigDecimal longitude = granaryLists.get(i).getLongitude();
			BigDecimal getLatitude = granaryLists.get(i).getLatitude();
			BigDecimal latitude1 = new BigDecimal(strArray[1]);
			BigDecimal latitude2 = new BigDecimal(strArray[0]);
			BigDecimal longitude1 = new BigDecimal(strArray[2]);
			BigDecimal longitude2 = new BigDecimal(strArray[3]);
			if(longitude.compareTo(latitude1)>=0 || longitude.compareTo(latitude2)<=0 ||
					getLatitude.compareTo(longitude1)>=0 || getLatitude.compareTo(longitude2)>=0){
				granarys.add(granaryLists.get(i));
			}
		}
		return granarys;
				
	}
	
	/**
	 * 加工企业地图位置
	 * @param moveLng
	 * @return
	 */
	@Expose 
	public List<Processors> getMoveProcessors(String moveLng){
		List<Processors> granaryLists = processorsData();
		List<Processors> granarys = new  ArrayList<Processors>();
		String[] strArray=moveLng.split(",");
		for (int i = 0; i < granaryLists.size(); i++) {
			BigDecimal longitude = granaryLists.get(i).getLongitude();
			BigDecimal getLatitude = granaryLists.get(i).getLatitude();
			BigDecimal latitude1 = new BigDecimal(strArray[1]);
			BigDecimal latitude2 = new BigDecimal(strArray[0]);
			BigDecimal longitude1 = new BigDecimal(strArray[2]);
			BigDecimal longitude2 = new BigDecimal(strArray[3]);
			if(longitude.compareTo(latitude1)>=0 || longitude.compareTo(latitude2)<=0 ||
					getLatitude.compareTo(longitude1)>=0 || getLatitude.compareTo(longitude2)>=0){
				granarys.add(granaryLists.get(i));
			}
		}
		return granarys;
				
	}
	/**
	 * 粮仓位置
	 * @return
	 */
	public  List<Granary>  granaryData(){
		List<Granary> granarys = new  ArrayList<Granary>();
		Granary  g1 = new Granary();
		g1.setId("1");
		g1.setLongitude(new BigDecimal(112.580632));
		g1.setLatitude(new BigDecimal(37.878936));
		g1.setName("太原市粮仓");
		g1.setPhone("13899996666");
		g1.setPrincipal("周华");
		granarys.add(g1);
		
		Granary  g2 = new Granary();
		g2.setId("2");
		g2.setLongitude(new BigDecimal(113.139719));
		g2.setLatitude(new BigDecimal(36.20508));
		g2.setName("长治市粮仓");
		g2.setPhone("13899997777");
		g2.setPrincipal("王方");
		granarys.add(g2);
		
		Granary  g3 = new Granary();
		g3.setId("3");
		g3.setLongitude(new BigDecimal(113.335767));
		g3.setLatitude(new BigDecimal(40.123378));
		g3.setName("大同市粮仓");
		g3.setPhone("13899998888");
		g3.setPrincipal("李志");
		granarys.add(g3);
		
		Granary  g4 = new Granary();
		g4.setId("4");
		g4.setLongitude(new BigDecimal(113.589099));
		g4.setLatitude(new BigDecimal(37.858352));
		g4.setName("阳泉市粮仓");
		g4.setPhone("13899994444");
		g4.setPrincipal("李凡");
		granarys.add(g4);
		
		return granarys;
	}
	
	/**
	 * 粮仓数据
	 * @return
	 */
	public  List<Foodstuff>  foodstuffData(){
		List<Foodstuff> foodstuffs = new  ArrayList<Foodstuff>();
		Foodstuff  f1 = new Foodstuff();
		f1.setId("1");
		f1.setName("大豆");
		f1.setTon("500");
		f1.setGranaryId("1");
		foodstuffs.add(f1);
		
		Foodstuff  f2 = new Foodstuff();
		f2.setId("2");
		f2.setName("玉米");
		f2.setTon("600");
		f2.setGranaryId("2");
		foodstuffs.add(f2);
		
		Foodstuff  f3 = new Foodstuff();
		f3.setId("3");
		f3.setName("小麦");
		f3.setTon("600");
		f3.setGranaryId("3");
		foodstuffs.add(f3);
		
		Foodstuff  f4 = new Foodstuff();
		f3.setId("4");
		f3.setName("红豆");
		f3.setTon("600");
		f3.setGranaryId("4");
		foodstuffs.add(f4);
		
		return foodstuffs;
	}
	
	/**
	 * 运输企业
	 * @return
	 */
	public  List<Transport>  transportData(){
		List<Transport> transports = new  ArrayList<Transport>();
		Transport t1 = new Transport();
		t1.setId("1");
		t1.setLongitude(new BigDecimal(112.568558));
		t1.setLatitude(new BigDecimal(37.838822));
		t1.setName("太原XX运输企业");
		t1.setPhone("12396668585");
		t1.setPrincipal("李虎");
		transports.add(t1);
		
		Transport t2 = new Transport();
		t2.setId("1");
		t2.setLongitude(new BigDecimal(113.101199));
		t2.setLatitude(new BigDecimal(36.179914));
		t2.setName("长治XX运输企业");
		t2.setPhone("12396668585");
		t2.setPrincipal("张飞");
		transports.add(t2);
		
		Transport t3 = new Transport();
		t3.setLongitude(new BigDecimal(113.341516));
		t3.setLatitude(new BigDecimal(40.106162));
		t3.setName("大同XX运输企业");
		t3.setPhone("12396668585");
		t3.setPrincipal("张飞");
		transports.add(t3);
		
		Transport t4 = new Transport();
		t4.setLongitude(new BigDecimal(113.591686));
		t4.setLatitude(new BigDecimal(37.866784));
		t4.setName("阳泉XX运输企业");
		t4.setPhone("12396668585");
		t4.setPrincipal("张飞");
		transports.add(t4);
		return transports;
	}
	
	/**
	 * 加工企业
	 * @return
	 */
	public  List<Processors>  processorsData(){
		List<Processors> processors = new  ArrayList<Processors>();
		Processors t1 = new Processors();
		t1.setId("1");
		t1.setLongitude(new BigDecimal(112.528314));
		t1.setLatitude(new BigDecimal(37.893517));
		t1.setName("太原XX加工企业");
		t1.setPhone("12396668585");
		t1.setPrincipal("李虎");
		processors.add(t1);
		
		Processors t2 = new Processors();
		t2.setId("1");
		t2.setLongitude(new BigDecimal(113.187437));
		t2.setLatitude(new BigDecimal(36.183642));
		t2.setName("长治XX加工企业");
		t2.setPhone("12396668585");
		t2.setPrincipal("张飞");
		processors.add(t2);
		
		Processors t3 = new Processors();
		t3.setId("1");
		t3.setLongitude(new BigDecimal(113.361063));
		t3.setLatitude(new BigDecimal(40.130881));
		t3.setName("大同XX加工企业");
		t3.setPhone("12396668585");
		t3.setPrincipal("张飞");
		processors.add(t3);
		
		Processors t4 = new Processors();
		t4.setId("1");
		t4.setLongitude(new BigDecimal(113.571277));
		t4.setLatitude(new BigDecimal(37.860403));
		t4.setName("阳泉XX加工企业");
		t4.setPhone("12396668585");
		t4.setPrincipal("张飞");
		processors.add(t4);
		return processors;
	}
	
	public  List<Vehicle> vehicleData(){
		List<Vehicle> transports = new  ArrayList<Vehicle>();
		Vehicle v1 = new Vehicle();
		v1.setId("1");
		v1.setName("李浩楠");
		v1.setPhone("18966663333");
		v1.setPrincipal("张斌");
		v1.setPlateNumber("F9982");
		transports.add(v1);
		
		Vehicle v2 = new Vehicle();
		v2.setId("1");
		v2.setName("李季");
		v2.setPhone("18966663333");
		v2.setPrincipal("张斌");
		v2.setPlateNumber("F9993");
		transports.add(v2);
		
		Vehicle v3 = new Vehicle();
		v3.setId("3");
		v3.setName("张达");
		v3.setPhone("18966663333");
		v3.setPrincipal("张斌");
		v3.setPlateNumber("F1103");
		transports.add(v3);
		
		Vehicle v4 = new Vehicle();
		v4.setId("4");
		v4.setName("白昆");
		v4.setPhone("18966663333");
		v4.setPrincipal("张斌");
		v4.setPlateNumber("F9233");
		transports.add(v4);
		
		return transports;
	}
}
